import './styles/reset.scss'

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'
import axios from 'axios'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import jQueryPlugin from './jquery.js'


const app = createApp(App)
app.use(ElementPlus, {
  locale: zhCn,
})
app.config.globalProperties.$axios = axios
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.use(createPinia())
app.use(jQueryPlugin)
app.use(router)

app.mount('#app')

//导航守卫、路由守卫、路由拦截
router.beforeEach((to, from, next) => {
  //验证token,只有存在token的时候，才能跳转到内容页
  let token = localStorage.getItem("token");
  if (token || to.path === '/login') {
    next();
  } else {
    ElMessage.error('登录失效')
    next("/login");
  }
  next();
})